#%%
%matplotlib inline
import seaborn as sns, matplotlib.pyplot as plt, numpy as np, scipy.optimize as op, pandas as pd
grains = ['dn', 'jo', 'mb', 'mk', 'pg', 'sf']
grains_new = {'dn': 'tg', 'jo': 'ng2', 'mb': 'ng3', 'mk': 'ng4', 'pg': 'ng5', 'sf': 'sf'}

df_aor = {}
for grain in grains:
    aor = pd.read_csv('observations/AOR/%s/%s_AoR.csv'%(grain, grain)).values[0]
    aor_arr = np.asarray(aor[1:]).astype(float)
    n = np.isfinite(aor_arr).sum()
    print(aor_arr.size)
    df_aor[grain] = {'mean': np.nanmean(aor_arr), 'se': np.nanstd(aor_arr)/np.sqrt(aor_arr.size)}
df_aor = pd.DataFrame(df_aor).T
aor = {grains_new[grain]: df_aor['mean'][grain] for grain in grains}
daor = {grains_new[grain]: df_aor.se[grain] for grain in grains}

df = pd.DataFrame({'std_angle': daor, 'mean_angle': aor})
df.to_csv('3_var_ARS_2022.csv')

# %%
